﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TransactionEditorDocument.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the TransactionEditorDocument type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Windows.Client.Documents
{
    using System;
    using System.Diagnostics.Contracts;
    using Common;
    using View;
    using ViewModel;

    /// <summary>
    /// Defines the <seealso cref="TransactionEditorDocument"/> type.
    /// </summary>
    public class TransactionEditorDocument : Document
    {
        /// <summary>
        /// Account editor view model
        /// </summary>
        private readonly TransactionEditorViewModel _viewModel;

        /// <summary>
        /// Initializes a new instance of the <see cref="TransactionEditorDocument"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        public TransactionEditorDocument(TransactionEditorViewModel viewModel)
            : base("Transaction")
        {
            Contract.Requires<ArgumentNullException>(viewModel != null);
            _viewModel = viewModel;
            View = new TransactionEditorView { DataContext = _viewModel };
            ContextMenuGroupName = "cmTransaction";

            MainWindowViewModel.SaveCommand.RegisterPotentialTarget(View.ActiveAwareness, _viewModel.SaveTransaction, _viewModel.CanSaveTransaction);
        }

        /// <summary>
        /// Documents the closed.
        /// </summary>
        public override void DocumentClosed()
        {
            MainWindowViewModel.SaveCommand.UnregisterPotentialTarget(View.ActiveAwareness);
        }
    }
}